package com.hnas.common.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hnas.account.util.AccCardConstants;
import com.hnas.activity.dto.DTOGetInvitationCodeForm;
import com.hnas.activity.dto.DTOGetInvitationCodeReceive;
import com.hnas.activity.dto.DTOGetInvitationForm;
import com.hnas.activity.dto.DTOInviRank;
import com.hnas.activity.dto.DTOInvitaionAddForm;
import com.hnas.api.domain.RouteFinalValue;
import com.hnas.appLogin.dto.search.RegisterAnymonusWsFromServer;
import com.hnas.appLogin.dto.search.RegisterAnymonusWsReceiveServer;
import com.hnas.common.outdto.AccNoForm;
import com.hnas.common.outdto.AccNoReceive;
import com.hnas.common.outdto.AnonyTransferRNameForm;
import com.hnas.common.outdto.DTOEmpId;
import com.hnas.common.outdto.FreeAmtSetDTO;
import com.hnas.common.outdto.GetBalanceForm;
import com.hnas.common.outdto.GetBalanceReceive;
import com.hnas.common.outdto.GetCardInfoByCardNoForm;
import com.hnas.common.outdto.GetCardInfoByCardNoReceive;
import com.hnas.common.outdto.GetHrEmployeeInfoReturn;
import com.hnas.common.outdto.GetLatestValidEmpAndCardReceive;
import com.hnas.common.outdto.GetTranByTranSnoForm;
import com.hnas.common.outdto.GetTranByTranSnoReceive;
import com.hnas.common.outdto.H5RechargeInitForm;
import com.hnas.common.outdto.InitOrderForm;
import com.hnas.common.outdto.InitOrderReturnReceive;
import com.hnas.common.outdto.LinkNetTradeForm;
import com.hnas.common.outdto.LinkNetTradeReceive;
import com.hnas.common.outdto.NoPassSetReceive;
import com.hnas.common.outdto.PasswordSetDTO;
import com.hnas.common.outdto.RechargePayForm;
import com.hnas.common.outdto.RechargePayReceive;
import com.hnas.common.outdto.SearchRecgPayInfoForm;
import com.hnas.common.outdto.SearchRecgPayInfoReceive;
import com.hnas.common.outdto.TranUserQRCodeByHttpForm;
import com.hnas.core.app_common.util.AESTool;
import com.hnas.core.app_common.util.CommonGetServerData;
import com.hnas.core.app_common.util.PostConnServer;
import com.hnas.core.app_common.util.PostKey;
import com.hnas.core.app_common.util.Result;
import com.hnas.core.util.StringUtil;

@Component("postServerInfoGet")
public class PostServerInfoGet {
	
	@Value("#{component['hr_infoagency']}")//发卡类型
	private String hrInfoagency;
	
	@Value("#{component['hr_key']}")//发卡类型
	private String hrKey;
	
	@Autowired
	private PostConnServer postConnServer;
	
	private static  AESTool aes = new AESTool();
	
	private static ObjectMapper objectMapper = new ObjectMapper();

	public  CommonReturn getNoPasswordInfo(String accNo) throws Exception{//getAccFreeAmtAndPassWord
			CommonReturn dtoResult = new CommonReturn();
			AccNoReceive accNoReceive = new AccNoReceive();
			AccNoForm accNoForm = new AccNoForm();
			accNoForm.setAccNo(accNo);
		    Map map = postConnServer.getRequestData(accNoForm, "APP_GetAccFreeAmtAndPassWord");
			JSON jsonData = (JSON) map.get("json");
			CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
			Result rs = cgsd.getResult();
			String rsdStr = rs.getResultCode();
			PostKey postKey = (PostKey) map.get("postKey");
			String key = postKey.getKey();
			if(rsdStr!=null&&rsdStr.equals("00000")){
				String resultData = rs.getResultData();
				if(StringUtil.isNotEmpty(resultData)){
			    	System.out.println("请求返回resultData:"+resultData);
			    	resultData = aes.decrypt(resultData,key );// 解密
					System.out.println("请求返回resultData解密:"+resultData);
					if(StringUtil.isNotEmpty(resultData)){
						resultData = resultData.toUpperCase();
						JSONObject jsonObject = JSONObject.parseObject(resultData);
						accNoReceive.setACC_NO((String)jsonObject.get("ACC_NO"));
						accNoReceive.setPASSWORD_SET((String)jsonObject.get("PASSWORD_SET"));
						if(jsonObject.containsKey("FREE_AMT")){
							accNoReceive.setFREE_AMT((String)jsonObject.get("FREE_AMT"));
						}else{
							accNoReceive.setFREE_AMT("0");
						}
					}
			    }
			}
			if(StringUtil.isNotEmpty(accNoReceive.getACC_NO())){
				dtoResult.setResultCode(ResultCode.SUCCESS);
				dtoResult.setResultData(accNoReceive);
				return dtoResult;
			}
			if(rsdStr!=null&&rsdStr.equals("50027")){
				dtoResult.setResultCode(ResultCode.SUCCESS);
				dtoResult.setResultData(accNoReceive);
				return dtoResult;
			}
	    return null;
	}
	
	/**
	 * 获取邀请码
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public  CommonReturn getInvitationCode(DTOGetInvitationCodeForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
		DTOGetInvitationCodeReceive dto = null;
	    Map map = postConnServer.getRequestData(form, "Activity_Invitation_GetInvitionCode");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String resultCode = rs.getResultCode();
		String resultMsg = rs.getResultMsg();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		String resultData = rs.getResultData();
		dtoResult.setResultCode(resultCode);
		dtoResult.setResultMsg(resultMsg);
		if(StringUtil.isNotEmpty(resultData)){
	    	System.out.println("请求返回resultData:"+resultData);
	    	resultData = aes.decrypt(resultData,key );// 解密
			System.out.println("请求返回resultData解密:"+resultData);
		}
		if(resultCode!=null&&resultCode.equals(ResultCode.SUCCESS)){
			if(StringUtil.isNotEmpty(resultData)){
				dto = objectMapper.readValue(resultData,DTOGetInvitationCodeReceive.class);
				dtoResult.setResultData(dto);
			}
		}
		
       return dtoResult;
}

	
	
	/**
	 * 查询排行榜
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public  CommonReturn getInvitationRanking(DTOGetInvitationForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
		List<DTOInviRank> list = new ArrayList<DTOInviRank>();	
		DTOInviRank dtoInviRank  = null;
	    Map map = postConnServer.getRequestData(form, "Activity_Invitation_findAllranking");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String resultCode = rs.getResultCode();
		String resultMsg = rs.getResultMsg();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		String resultData = rs.getResultData();
		dtoResult.setResultCode(resultCode);
		dtoResult.setResultMsg(resultMsg);
		if(StringUtil.isNotEmpty(resultData)){
	    	System.out.println("请求返回resultData:"+resultData);
	    	resultData = aes.decrypt(resultData,key );// 解密
			System.out.println("请求返回resultData解密:"+resultData);
		}
		if(resultCode!=null&&resultCode.equals(ResultCode.SUCCESS)){
			if(StringUtil.isNotEmpty(resultData)){
				JSONArray jsonArray = JSONArray.parseArray(resultData);
				
				Iterator<Object> it = jsonArray.iterator();
				while(it.hasNext()){
					 JSONObject jo = (JSONObject) it.next();
					 dtoInviRank = new DTOInviRank();
					 dtoInviRank.setRanking(jo.getString("rank"));		
					 dtoInviRank.setTotal(jo.getString("total"));
					 dtoInviRank.setWx_image("");
					 dtoInviRank.setWx_name("");
					 String elements = jo.getString("elments");
					 if(StringUtil.isNotEmpty(elements)){
						 JSONObject getWxElements=JSONObject.parseObject(elements);
						 if(null!=getWxElements){
							 if(getWxElements.containsKey("wx_image")){
								 dtoInviRank.setWx_image(getWxElements.getString("wx_image"));
							 }
							 
							 if(getWxElements.containsKey("wx_name")){
								 dtoInviRank.setWx_name(getWxElements.getString("wx_name"));
							 }
						 }
					 }
					 if(form.getInvitationId().equals(jo.getString("invitationId"))){
						 dtoInviRank.setIsSelf("1");//自己的排行信息
					 }else{
						 dtoInviRank.setIsSelf("0");
					 }
					 
					 list.add(dtoInviRank);
				}
				System.out.println(list.toString());
				dtoResult.setResultData(list);
			}
		}
		
       return dtoResult;
}
	
	
	
	/**
	 * 增添活动邀请记录
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public  CommonReturn addInvitation(DTOInvitaionAddForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
		AccNoReceive accNoReceive = new AccNoReceive();
	    Map map = postConnServer.getRequestData(form, "Activity_Invitation_addInvitaion");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			dtoResult.setResultCode(ResultCode.SUCCESS);
			dtoResult.setResultData(accNoReceive);
			return dtoResult;
		}
      return null;
}
	
	/**
	 * H5支付生成订单
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public  CommonReturn getH5Recharge(H5RechargeInitForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
		RechargePayReceive receive = new RechargePayReceive();
	    Map map = postConnServer.getRequestData(form, RouteFinalValue.APP_H5RechargeInit);
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					receive = objectMapper.readValue(resultData, RechargePayReceive.class);
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(receive);
					return dtoResult;
				}
		    }
		}
		if(rsdStr!=null&&rsdStr.equals("50009")){
			dtoResult.setResultCode(ResultCode.ERROR_133);
			return dtoResult;
		}
    return null;
}
	
	public  CommonReturn getRechargeReturn(InitOrderForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
		InitOrderReturnReceive receive = new InitOrderReturnReceive();
	    Map map = postConnServer.getRequestData(form, RouteFinalValue.APP_RechargeInit);
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					receive = objectMapper.readValue(resultData, InitOrderReturnReceive.class);
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(receive);
					return dtoResult;
					//resultData = resultData.toUpperCase();
					//JSONObject jsonObject = JSONObject.fromObject(resultData);
				}
		    }
		}
		if(rsdStr!=null&&rsdStr.equals("50009")){
			dtoResult.setResultCode(ResultCode.ERROR_133);
			return dtoResult;
		}
    return null;
}
	
	public  CommonReturn getBalanceInfo(String cardNo,String subCode) throws Exception{
			CommonReturn dtoResult = new CommonReturn();
			GetBalanceReceive getBalanceReceive = new GetBalanceReceive();
			getBalanceReceive.setBALANCE("0.0");
			GetBalanceForm getBalanceForm = new GetBalanceForm();
			getBalanceForm.setCardNo(cardNo);
			getBalanceForm.setSubCode(subCode);
		    Map map = postConnServer.getRequestData(getBalanceForm, "APP_GetAccBalanceByCardNo");
			JSON jsonData = (JSON) map.get("json");
			CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
			Result rs = cgsd.getResult();
			String rsdStr = rs.getResultCode();
			PostKey postKey = (PostKey) map.get("postKey");
			String key = postKey.getKey();
//			if(rsdStr!=null&&rsdStr.equals("50027")){
//				dtoResult.setResultCode(ResultCode.SUCCESS);
//				dtoResult.setResultData(getBalanceReceive);
//				return dtoResult;
//			}
			if(rsdStr!=null&&rsdStr.equals("00000")){
				String resultData = rs.getResultData();
				if(StringUtil.isNotEmpty(resultData)){
			    	System.out.println("请求返回resultData:"+resultData);
			    	resultData = aes.decrypt(resultData,key );//解密
					System.out.println("请求返回resultData解密:"+resultData);
					if(StringUtil.isNotEmpty(resultData)){
						resultData = resultData.toUpperCase();
						resultData = resultData.substring(resultData.indexOf("[")+1, resultData.indexOf("]"));
						JSONObject jsonObject = JSONObject.parseObject(resultData);
						if(jsonObject.containsKey("FREE_AMT")){
							getBalanceReceive.setFREE_AMT((String)jsonObject.get("FREE_AMT"));
						}
						if(jsonObject.containsKey("SUB_CODE")){
							getBalanceReceive.setSUB_CODE((String)jsonObject.get("SUB_CODE"));
						}
						if(jsonObject.containsKey("PAYMENT_STAT")){
							getBalanceReceive.setPAYMENT_STAT((String)jsonObject.get("PAYMENT_STAT"));
						}
						if(jsonObject.containsKey("MAX_BALANCE")){
							getBalanceReceive.setMAX_BALANCE((String)jsonObject.get("MAX_BALANCE"));
						}
						if(jsonObject.containsKey("SECRET_SET")){
							getBalanceReceive.setSECRET_SET((String)jsonObject.get("SECRET_SET"));
						}
						if(jsonObject.containsKey("BALANCE")){
							if(StringUtil.isEmpty((String)jsonObject.get("BALANCE"))){
								getBalanceReceive.setBALANCE("0.0");
							}else{
								getBalanceReceive.setBALANCE((String)jsonObject.get("BALANCE"));
							}
						}
						if(jsonObject.containsKey("SUB_NAME")){
							getBalanceReceive.setSUB_NAME((String)jsonObject.get("SUB_NAME"));
						}
						//getBalanceReceive = objectMapper.readValue(resultData, GetBalanceReceive.class);
					}
			    }
				dtoResult.setResultCode(ResultCode.SUCCESS);
				dtoResult.setResultData(getBalanceReceive);
				return dtoResult;
			}
			return null;
	}
	
	public  CommonReturn noPasswordSet(FreeAmtSetDTO freeAmtSetDTO,PasswordSetDTO passwordSetDTO,String type) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		NoPassSetReceive noPassSetReceive = new NoPassSetReceive();
		Map map = new HashMap();
		if(AccCardConstants.PASSWORD_SET.equals(type)){
			map = postConnServer.getRequestData(passwordSetDTO, "APP_UpdateAccFreeAmt");
		}else {
			map = postConnServer.getRequestData(freeAmtSetDTO, "APP_UpdateAccFreeAmt");
		}
	  //  map = postConnServer.getRequestData(noPassSetFrom, "APP_UpdateAccFreeAmt");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );//解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					resultData = resultData.toUpperCase();
					JSONObject jsonObject = JSONObject.parseObject(resultData);
					if(jsonObject.containsKey("FREE_AMT")){
						noPassSetReceive.setFREE_AMT((String)jsonObject.get("FREE_AMT"));
					}else{
						noPassSetReceive.setFREE_AMT("0");
					}
					//ACC_NO
					noPassSetReceive.setACC_NO((String)jsonObject.get("ACC_NO"));
				}
		    }
			dtoResult.setResultCode(ResultCode.SUCCESS);
			 dtoResult.setResultMsg(ResultCode.getResultValue(ResultCode.SUCCESS));
			dtoResult.setResultData(noPassSetReceive);
			return dtoResult;
		}
		if(rsdStr!=null&&rsdStr.equals("50027")){
			dtoResult.setResultCode(ResultCode.SUCCESS);
			 dtoResult.setResultMsg(ResultCode.getResultValue(ResultCode.SUCCESS));
			dtoResult.setResultData(noPassSetReceive);
			return dtoResult;
		}
		if(rsdStr!=null&&rsdStr.equals("50024")){
			 dtoResult.setResultCode(ResultCode.ERROR_034);
			 dtoResult.setResultMsg(ResultCode.getResultValue(ResultCode.ERROR_034));
			return dtoResult;
		}
		return null;
}
	
	public static void main(String[] args) throws Exception {
//		RechargePayForm sForm = new RechargePayForm();
//		sForm.setSwiftNumber("071220170329476125899730000000054964gnb");
//		sForm.setMerchantId("10005");
//		rechargePay(sForm);5899730000000054964
		//getBalanceInfo("5899730000000086453", "224102");
		//GetTranByTranSnoForm  form = new GetTranByTranSnoForm();
		//form.setTranSno("00000000000000000000000004758699");
		//GetTranInfoByTranSno(form);
		
		//getEmployeeInfo
	}
	
	public  CommonReturn getCardObj(String cardType,String merchantId,String pwd) throws Exception{
			CommonReturn dtoResult = new CommonReturn();
			RegisterAnymonusWsFromServer registerAnymonusWsFromServer = null;
			RegisterAnymonusWsReceiveServer receiveServer = new RegisterAnymonusWsReceiveServer();
			receiveServer.setCardKind(cardType);
			receiveServer.setMerchantId(merchantId);
			receiveServer.setPwd(pwd);
		    Map map = postConnServer.getRequestData(receiveServer, "APP_RegisterAnymonusWs");
			JSON jsonData = (JSON) map.get("json");
			CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
			Result rs = cgsd.getResult();
			String rsdStr = rs.getResultCode();
			PostKey postKey = (PostKey) map.get("postKey");
			String key = postKey.getKey();
			if(rsdStr!=null&&rsdStr.equals("00000")){
				String resultData = rs.getResultData();
				if(StringUtil.isNotEmpty(resultData)){
			    	System.out.println("请求返回resultData:"+resultData);
			    	resultData = aes.decrypt(resultData,key );// 解密
					System.out.println("请求返回resultData解密:"+resultData);
					if(StringUtil.isNotEmpty(resultData)){
						resultData = resultData.toLowerCase();
						registerAnymonusWsFromServer = objectMapper.readValue(resultData, RegisterAnymonusWsFromServer.class);
					}
			    }
			}
			if(null!=registerAnymonusWsFromServer&&StringUtil.isNotEmpty(registerAnymonusWsFromServer.getCard_no())){
				dtoResult.setResultCode(ResultCode.SUCCESS);
				dtoResult.setResultData(registerAnymonusWsFromServer);
				return dtoResult;
			}
			if(rsdStr!=null&&rsdStr.equals("50027")){
				dtoResult.setResultCode(ResultCode.SUCCESS);
				dtoResult.setResultData(registerAnymonusWsFromServer);
				return dtoResult;
			}
			return null;
	}
	
	
	/**
	 * 生成订单
	 */
	public  CommonReturn initOrder(InitOrderForm form) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		InitOrderReturnReceive returnDTO = new InitOrderReturnReceive();
	    Map map = postConnServer.getRequestData(form, "APP_RechargeInit");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					
					//resultData = resultData.toLowerCase();
					try {
					returnDTO = objectMapper.readValue(resultData, InitOrderReturnReceive.class);
						//returnDTO.parseFromJson(resultData);
					} catch (Exception e) {
					 e.printStackTrace();
					}
					
				}
		    }
		}
		
		if(rsdStr!=null&&rsdStr.equals("50009")){
			dtoResult.setResultCode(ResultCode.ERROR_133);
			return dtoResult;
		}
		
		if(StringUtil.isNotEmpty(returnDTO.getSwiftNumber())){
			dtoResult.setResultCode(ResultCode.SUCCESS);
			dtoResult.setResultData(returnDTO);
			return dtoResult;
		}
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
}
	
	/**
	 * H5充值支付
	 */
	public  CommonReturn H5RechargePay(RechargePayForm form) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		RechargePayReceive returnDTO = new RechargePayReceive();
	    Map map = postConnServer.getRequestData(form, "APP_H5Recharging");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					returnDTO = objectMapper.readValue(resultData, RechargePayReceive.class);
				}
		    }
		}
		if(StringUtil.isNotEmpty(returnDTO.getSwiftNumber())){
			dtoResult.setResultCode(ResultCode.SUCCESS);
			dtoResult.setResultData(returnDTO);
			return dtoResult;
		}
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
   }
	
	/**
	 * 充值支付
	 */
	public  CommonReturn rechargePay(RechargePayForm form) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		RechargePayReceive returnDTO = new RechargePayReceive();
	    Map map = postConnServer.getRequestData(form, "APP_Recharging");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					returnDTO = objectMapper.readValue(resultData, RechargePayReceive.class);
				}
		    }
		}
		if(StringUtil.isNotEmpty(returnDTO.getSwiftNumber())){
			dtoResult.setResultCode(ResultCode.SUCCESS);
			dtoResult.setResultData(returnDTO);
			return dtoResult;
		}
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
   }
	
	/**
	 * 查询充值交易情况订单
	 */
	public  CommonReturn searchRecgPayInfo(SearchRecgPayInfoForm form) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		SearchRecgPayInfoReceive returnDTO = new SearchRecgPayInfoReceive();
	    Map map = postConnServer.getRequestData(form, "APP_RechargeQuery");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&& (rsdStr.equals("00000") || rsdStr.equals("50039"))){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					JSONObject jo = JSONObject.parseObject(resultData);
					returnDTO.setAmount(jo.getString("amount"));
					returnDTO.setResultCode(jo.getString("resultCode"));
					returnDTO.setResultMsg(jo.getString("resultMsg"));
					returnDTO.setCardNo(jo.getString("cardId"));
					if(null==jo.getString("prepayid")){
						returnDTO.setPrepayid("");
					}else{
						returnDTO.setPrepayid(jo.getString("prepayid"));
					}
					returnDTO.setSwiftNumber(jo.getString("swiftNumber"));//swiftNumber
					try {
						returnDTO.setTradeState(jo.getLong("tradeState")+"");
					} catch (Exception e) {
						e.printStackTrace();
					}
					
					returnDTO.setTransTime(jo.getString("transTime"));
					returnDTO.setRechargeStatus(jo.getLong("rechargeStatus")+"");
					returnDTO.setMerchantId(jo.getLong("merchantId")+"");
					returnDTO.setRechargeNum(jo.getString("rechargeNum"));
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(returnDTO);
					return dtoResult;
				}
		    }
		}
		
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
   }
	
	public  CommonReturn tranUserQRCodeByHttp(TranUserQRCodeByHttpForm form) throws Exception{//getAccFreeAmtAndPassWord
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(form, "APP_TranUserQRCodeByHttp");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					dtoResult.setResultCode(ResultCode.SUCCESS);
					return dtoResult;
				}
		    }
		  }
         return null;
      }
	
	/**
	 * 根据交易流水号获取交易信息
	 */
	public  CommonReturn GetTranInfoByTranSno(GetTranByTranSnoForm form) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
		GetTranByTranSnoReceive returnDTO = new GetTranByTranSnoReceive();
	    Map map = postConnServer.getRequestData(form, "APP_GetTranByTranSno");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					returnDTO = objectMapper.readValue(resultData, GetTranByTranSnoReceive.class);
					System.out.println(returnDTO);
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(returnDTO);
					return dtoResult;
				}
		    }
		}
		
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
   }
	
	/**
	 * 联机交易
	 */
	public  CommonReturn linkNetTrade(LinkNetTradeForm form) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
		LinkNetTradeReceive returnDTO = new LinkNetTradeReceive();
	    Map map = postConnServer.getRequestData(form, "APP_LinkNetTrade");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					resultData = resultData.toLowerCase();
					returnDTO = objectMapper.readValue(resultData, LinkNetTradeReceive.class);
					System.out.println(returnDTO);
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(returnDTO);
					return dtoResult;
				}
		    }
		}
		if(rsdStr!=null&&rsdStr.equals("50010")){
			dtoResult.setResultCode(ResultCode.ERROR_086);
			return dtoResult;
		}
		
		
		if(rsdStr!=null&&rsdStr.equals("50024")){
			dtoResult.setResultCode(ResultCode.ERROR_034);
			return dtoResult;
		}
		
		dtoResult.setResultCode(ResultCode.FAIL);
		dtoResult.setResultData(returnDTO);
		return dtoResult;
   }
	
	public CommonReturn getEmployeeInfo(String username,String password) throws Exception{
		CommonReturn dtoResult = new CommonReturn();
		System.out.println("=====================开始查询员工信息：=========================");
		Map<String, String> map = null;
		try {
		HttpClient httpClient = HttpClientBuilder.create().build();
		HttpPost httpPost = new HttpPost(hrInfoagency);
		httpPost.addHeader("content-type", "application/json");
		httpPost.addHeader("accept", "application/json");
		byte[] key = ConvertUtil.strArr2byteArr(ConvertUtil.Str2Arr(hrKey));
		username = ConvertUtil.byte2hex(RSATool.trides_crypt(username.getBytes(),key));
		password = ConvertUtil.byte2hex(RSATool.trides_crypt(password.getBytes(),key));
		Map<String, Object> par = new HashMap<String, Object>();
		par.put("account", username);
		par.put("pwd", password);
		ObjectMapper objectMapper = new ObjectMapper();
			String json = objectMapper.writeValueAsString(par);
			StringEntity entity = new StringEntity(json);
			httpPost.setEntity(entity);
			HttpResponse httpResponse = httpClient.execute(httpPost);
			String response = EntityUtils.toString(httpResponse.getEntity());
			System.out.println("查询域账号信息："+response);
			map = objectMapper.readValue(response, Map.class);
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("=====================成功结束查询员工信息：=========================");
			return returnFail(dtoResult);
		}
		if(map==null){
			return returnFail(dtoResult);
		}
		GetHrEmployeeInfoReturn dto = new GetHrEmployeeInfoReturn();
		dto.setResult(map.get("Result"));
		dto.setcFlag(map.get("cFlag"));
		dto.setEmployeeId(map.get("vcEmployeeID"));
		if(StringUtil.isEmpty(dto.getResult()) && StringUtil.isEmpty(dto.getcFlag())){
			return returnFail(dtoResult);
		}
		if(dto.getcFlag() != null && !dto.getcFlag().equals("1")){
			return returnFail(dtoResult);
		}
		if(StringUtil.isEmpty(dto.getEmployeeId())){
			return returnFail(dtoResult);
		}
		DTOEmpId form = new DTOEmpId();
		form.setEmpId(dto.getEmployeeId());
		GetLatestValidEmpAndCardReceive returnDTO = new GetLatestValidEmpAndCardReceive();
	    Map map1 = postConnServer.getRequestData(form, "APP_GetLatestValidEmpAndCard");
		JSON jsonData = (JSON) map1.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map1.get("postKey");
		String key1 = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key1);// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					//resultData = resultData.toLowerCase();
					returnDTO = objectMapper.readValue(resultData, GetLatestValidEmpAndCardReceive.class);
					System.out.println(returnDTO);
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(returnDTO);
					System.out.println("=====================成功结束查询员工信息：=========================");
					return dtoResult;
				}
		    }
		}
		if(ResultCode.ERROR_60002.equals(rsdStr)){
			dtoResult.setResultCode(ResultCode.ERROR_60002);
			return dtoResult;
		}
		
		System.out.println("=====================失败结束查询员工信息：=========================");
		return returnFail(dtoResult);
	}
	
	public  CommonReturn getLatestValidEmpAndCard(AnonyTransferRNameForm form) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(form, "APP_AnonymousTransfer");
		JSON jsonData = (JSON) map.get("json");
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					JSONObject jsonObject = JSONObject.parseObject(resultData);
					if(jsonObject.containsKey("resultCode")&&ResultCode.SUCCESS.equals(jsonObject.getString("resultCode"))){
						if(jsonObject.containsKey("checkResult")&&"true".equals(jsonObject.getString("checkResult"))){
							dtoResult.setResultCode(ResultCode.SUCCESS);
							return dtoResult;
						}
					}
				}
		    }
		}
		
		dtoResult.setResultCode(ResultCode.FAIL);
		return dtoResult;
   }
	
	/**
	 * 通过卡号查询卡信息
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public  CommonReturn GetCardInfoByCardNo(GetCardInfoByCardNoForm form) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(form, "APP_GetCardInfoByCardNo");
		JSON jsonData = (JSON) map.get("json");
		GetCardInfoByCardNoReceive receive = new GetCardInfoByCardNoReceive();
		CommonGetServerData cgsd = JSON.toJavaObject(jsonData, CommonGetServerData.class);//json转实体类
		Result rs = cgsd.getResult();
		String rsdStr = rs.getResultCode();
		PostKey postKey = (PostKey) map.get("postKey");
		String key = postKey.getKey();
		if(rsdStr!=null&&rsdStr.equals("00000")){
			String resultData = rs.getResultData();
			if(StringUtil.isNotEmpty(resultData)){
		    	System.out.println("请求返回resultData:"+resultData);
		    	resultData = aes.decrypt(resultData,key );// 解密
				System.out.println("请求返回resultData解密:"+resultData);
				if(StringUtil.isNotEmpty(resultData)){
					JSONObject jsonObject = JSONObject.parseObject(resultData);
					receive.setACC_NO(jsonObject.getString("ACC_NO"));
					receive.setANONYMOUS_STAT(jsonObject.getString("ANONYMOUS_STAT"));//
					receive.setCARD_KIND(jsonObject.getString("CARD_KIND"));
					receive.setCARD_MARK(jsonObject.getString("CARD_MARK"));
					receive.setCARD_NO(jsonObject.getString("CARD_NO"));
					receive.setCARD_STAT(jsonObject.getString("CARD_STAT"));
					dtoResult.setResultCode(ResultCode.SUCCESS);
					dtoResult.setResultData(receive);
					return dtoResult;
				}
		    }
		}
		
		dtoResult.setResultCode(ResultCode.FAIL);
		return dtoResult;
   }
	
	private CommonReturn returnFail(CommonReturn dtoResult){
		dtoResult.setResultCode(ResultCode.FAIL);
		return dtoResult;
	}
	
	
	/**
	 * 发送微信交易提醒-宝岛通
	 */
	public  CommonReturn SendWxModelMsgBdt(Object object) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(object, RouteFinalValue.SendWxModelMsgBdt);
		return dtoResult;
   }
	
	/**
	 * 发送微信交易提醒-宝岛通
	 */
	public  CommonReturn SendWxBuyCardMsgBdt(Object object) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(object, RouteFinalValue.SendWxBuyCardMsgBdt);
		return dtoResult;
   }
	
	/**
	 * 发送微信交易提醒-宝岛通
	 */
	public  CommonReturn SendWxReceiveCardMsgBdt(Object object) throws Exception {
		CommonReturn dtoResult = new CommonReturn();
	    Map map = postConnServer.getRequestData(object, RouteFinalValue.SendWxReceiveCardMsgBdt);
		return dtoResult;
   }
	
}
